package com.yswy.domain.entity;

import com.alibaba.fastjson2.JSONArray;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.zip.CRC32;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("app 用户")
@TableName(value = "ip_place")
public class IpPlace {
    @TableId(type = IdType.AUTO)
    private Long id ;
    @ApiModelProperty("ip")
    private String createIp;
    @ApiModelProperty("ipcrc")
    private Long createIpCrc;
    @ApiModelProperty("datas")
    private String placeDatas;
    @ApiModelProperty("国家")
    private String country;
    @ApiModelProperty("省份")
    private String province;
    @ApiModelProperty("市籍")
    private String city;
    @ApiModelProperty("区")
    private String area;
    @ApiModelProperty("服务商")
    private String serviceProvider;
    @ApiModelProperty("邮编")
    private String zipCode;
    @ApiModelProperty("区号")
    private String areaCode;
    @ApiModelProperty("创建时间")
    private Date createTime = new Date();

    public IpPlace(String createIp, String dates , String a) {
        this.createIp = createIp;
        CRC32 crc32 = new CRC32();
        crc32.update(createIp.getBytes());
        this.createIpCrc = crc32.getValue();
        this.placeDatas = dates ;
        try {
            JSONArray jsonArray = JSONArray.parseArray(dates);
            this.country = jsonArray.getString(0);
            this.province = jsonArray.getString(1);
            this.city = jsonArray.getString(2);
            this.area = jsonArray.getString(3);
            this.serviceProvider = jsonArray.getString(4);
            this.zipCode = jsonArray.getString(5);
            this.areaCode = jsonArray.getString(6);
        }catch (Exception e){

        }
        this.createTime = new Date();
    }

    public IpPlace(String createIp, String dates) {
        this.createIp = createIp;
        CRC32 crc32 = new CRC32();
        crc32.update(createIp.getBytes());
        this.createIpCrc = crc32.getValue();
        this.placeDatas = dates ;
        this.createTime = new Date();
    }
}
